package com.example.mybatisfinaltask.service.impl;

import com.example.mybatisfinaltask.mapper.EmpMapper;
import com.example.mybatisfinaltask.pojo.Emp;
import com.example.mybatisfinaltask.pojo.PageBean;
import com.example.mybatisfinaltask.service.EmpService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;
//    @Override
//    public PageBean pageSelect(Integer page, Integer pageSize) {
//        List<Emp>Emplist=empMapper.getPageFind((page-1)*pageSize,pageSize);
//        Integer count=empMapper.getCount();
//        return new PageBean(count,Emplist);
//    }
    @Override
    public PageBean pageSelect(Integer page, Integer pageSize, String name, Short gender, LocalDate begin, LocalDate end) {
        PageHelper.startPage(page,pageSize);
        List<Emp>list=empMapper.selectAll( name,  gender,  begin, end);
        Page<Emp>p=(Page<Emp>) list;
        return new PageBean(p.getTotal(),p.getResult());
    }

    @Override
    public void batchDelete(Integer[] ids) {
        empMapper.batchDelete(ids);
    }

    @Override
    public void add(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.add(emp);
    }

    @Override
    public Object getById(Integer id) {
        return empMapper.getById(id);
    }

    @Override
    public void modify(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.modify(emp);
    }

    @Override
    public Emp vertifyLogin(Emp emp) {
        return empMapper.vertifyLogin(emp);
    }
}
